
<template>
  <a-layout id="app" v-loading="loading" style="min-height: 100vh">
    <leftVue :mode="mode"></leftVue>
    <a-layout v-if="!loading">
      <a-layout-header class="a-layout-header">
        <a-breadcrumb class="align-middle">
          <a-breadcrumb-item>
            <router-link :to="{name:'首页'}">首页</router-link>
          </a-breadcrumb-item>
          <a-breadcrumb-item v-for="(v,i) in breadcrumb" :key="i">
            <router-link :to="{name:v.name}" v-text="v.name"></router-link>
          </a-breadcrumb-item>
        </a-breadcrumb>
      </a-layout-header>
      <keep-alive :max="10">
        <router-view class="admin-ant-layout"></router-view>
      </keep-alive>
    </a-layout>
  </a-layout>
</template>

<script>
import leftVue from "@/components/admin/left.vue";
import { mapActions } from "vuex";
export default {
  name: "admin",
  data() {
    return {
      mode: false,
      loading: true
    };
  },
  computed: {
    breadcrumb() {
      const { fullPath } = this.$route;
      const arr = [];
      const arrPath = fullPath.split("/");
      for (let v = 1; v < arrPath.length; v++) {
        const brrPath = fullPath.split("/");
        const str = brrPath.splice(1, v).join("/");
        const data = this.$router.match(str);
        console.log(data)
        arr.push(data);
      }
      return arr;
    }
  },
  async mounted() {
    this.start();
  },
  methods: {
    async start() {
      this.loading = true;
      let sess = await this.session();
      if (!sess) {
        this.$message("没有登录或没有权限");
        this.$router.push("/login");
        return;
      }
      Promise.all([
        this.actionUser(),
        this.actionCourse(),
        this.actionPackege(),
        this.actionCatebag(),
        this.actionCatebagtype(),
        this.actionFileurl(),
        this.actionIframe(),
        this.actionCoursecatebag(),
        this.actionSecretfile(),
        this.actionTeacherproposal(),
        this.actionTpdata(),
        this.actionVideoCategories()
      ]).then(() => {
        this.loading = false;
      });
    },
    ...mapActions([
      "session",
      "actionUser",
      "actionCourse",
      "actionPackege",
      "actionCatebag",
      "actionCatebagtype",
      "actionFileurl",
      "actionIframe",
      "actionCoursecatebag",
      "actionSecretfile",
      "actionTeacherproposal",
      "actionTpdata",
      "actionItembank",
      "actionItembankgroup",
      "actionItembankitembankgroup",
      "actionTeacheritembanks",
      "actionVideoCategories"
    ])
  },
  components: {
    leftVue
  }
};
</script>

<style scoped>
#app .a-layout-header {
  background-color: #ffffff;
  padding-left: 20px;
}
.align-middle {
  line-height: 64px;
}
</style>
